log using log_ethnic_ineq_reg.log, replace
clear all
**Set working directory to location of files**
*cd "location"

use "Main dataset.dta"

**Install packages required for analyses and plotting**
ssc install estout, replace
ssc install mediation, replace
ssc install coefplot, replace
ssc install tsspell, replace
ssc install interflex, replace
ssc install spmap, replace

*****************************************************************
************* Preparation of variables for analysis *************
*****************************************************************

*** Democratic transitions and breakdowns with Lexical level 4 ***
* Level 4 variable
gen lexical_index_4= 1 if lexical_index >= 4
replace lexical_index_4 = 0 if lexical_index <=3
replace lexical_index_4 = . if lexical_index ==.

*** Transition lexical 4 without international/foreign involvement
gen transition_lexical_4 = 0
replace transition_lexical_4 = 1 if lexical_index_4==1 & L.lexical_index_4==0 & transition_type!=4 & transition_type!=5
replace transition_lexical_4 =. if lexical_index_4==.

*** Breakdown Lexical level 4 without international/foreign involvement
gen breakdown_lexical_4 = 0
replace breakdown_lexical_4 =1 if lexical_index_4==0 & L.lexical_index_4==1 & breakdown_type!=3
replace breakdown_lexical_4 =. if lexical_index_4==. 



*** Democratic transitions and breakdowns with Lexical level 5 ***
* Level 5 variable
gen lexical_index_5= 1 if lexical_index >= 5
replace lexical_index_5 = 0 if lexical_index <=4
replace lexical_index_5 = . if lexical_index ==.

*** Transition lexical 5 without international/foreign involvement
gen transition_lexical_5 = 0
replace transition_lexical_5 = 1 if lexical_index_5==1 & L.lexical_index_5==0 & transition_type!=4 & transition_type!=5
replace transition_lexical_5 =. if lexical_index_5==.

*** Breakdown Lexical level 5 without international/foreign involvement
gen breakdown_lexical_5 = 0
replace breakdown_lexical_5 =1 if lexical_index_5==0 & L.lexical_index_5==1 & breakdown_type!=3
replace breakdown_lexical_5 =. if lexical_index_5==. 



*** Democratic transitions and breakdowns with Lexical level 6 ***
* Level 6 variable
gen lexical_index_6= 1 if lexical_index == 6
replace lexical_index_6 = 0 if lexical_index <=5
replace lexical_index_6 = . if lexical_index ==.

*** Transition lexical 6 without international/foreign involvement
gen transition_lexical_6 = 0
replace transition_lexical_6 = 1 if lexical_index_6==1 & L.lexical_index_6==0 & transition_type!=4 & transition_type!=5
replace transition_lexical_6 =. if lexical_index_6==.

*** Breakdown Lexical level 6 without international/foreign involvement
gen breakdown_lexical_6 = 0
replace breakdown_lexical_6 =1 if lexical_index_6==0 & L.lexical_index_6==1 & breakdown_type!=3
replace breakdown_lexical_6 =. if lexical_index_6==. 



*** Democratic transitions and breakdowns with Boix, Miller and Rosato ***
*** Transition
gen transition_boix = 0
replace transition_boix = 1 if e_boix_regime==1 & L.e_boix_regime==0
replace transition_boix =. if e_boix_regime==.

*** Breakdown
gen breakdown_boix = 0
replace breakdown_boix =1 if e_boix_regime==0 & L.e_boix_regime==1
replace breakdown_boix =. if e_boix_regime==.



*** Years democratic
tsspell lexical_index_5
g years_democratic = 0
replace years_democratic = _seq if lexical_index_5==1
replace years_democratic = L.years_democratic+1 if breakdown_lexical_5==1

* Polynomials
g years_democratic_2 = years_democratic^2
g years_democratic_3 = years_democratic^3


*** Years autocratic
g autocratic_lexical_5 = .
replace autocratic_lexical_5 = 0 if lexical_index_5 ==1
replace autocratic_lexical_5 = 1 if lexical_index_5 == 0
* Clear
drop _spell _seq _end
tsspell autocratic_lexical_5
g years_autocratic = 0
replace years_autocratic = _seq if autocratic_lexical_5==1
replace years_autocratic = L.years_autocratic+1 if transition_lexical_5==1
* Polynomials
g years_autocratic_2 = years_autocratic^2
g years_autocratic_3 = years_autocratic^3


*** Regional share of democracies
* LIED 5
g dummy=1 if lexical_index_5!=.
bys e_regionpol_6C year: egen nrcon=sum(dummy)
bys e_regionpol_6C year: egen dsum=sum(lexical_index_5)
g region_lexical_5=(dsum-lexical_index_5)/(nrcon-1)
sort country_id year
drop dummy nrcon dsum

* BMR
g dummy=1 if e_boix_regime!=.
bys e_regionpol_6C year: egen nrcon=sum(dummy)
bys e_regionpol_6C year: egen dsum=sum(e_boix_regime)
g region_bmr=(dsum-e_boix_regime)/(nrcon-1)
sort country_id year
drop dummy nrcon dsum

* LIED 4
g dummy=1 if lexical_index_4!=.
bys e_regionpol_6C year: egen nrcon=sum(dummy)
bys e_regionpol_6C year: egen dsum=sum(lexical_index_4)
g region_lexical_4=(dsum-lexical_index_4)/(nrcon-1)
sort country_id year
drop dummy nrcon dsum

* LIED 6
g dummy=1 if lexical_index_6!=.
bys e_regionpol_6C year: egen nrcon=sum(dummy)
bys e_regionpol_6C year: egen dsum=sum(lexical_index_6)
g region_lexical_6=(dsum-lexical_index_6)/(nrcon-1)
sort country_id year



********** Rescaling of variables ***************

*** Rescale to range from 0-1 and - in some cases - to ensure that normatively negative receive higher values for all variables

***rescale V-Dem to go from 0-1 with lower values being normatively better
generate SEI = ((v2peapssoc-3.37)/(-3.135-3.37)*(1-0)+0)

* Mass mobilization (C) (v2cagenmob) [0-1]
g v2cagenmob_2 = ((v2cagenmob--3.634)/(3.971--3.634))*(1-0)+0

* Mobilization for democracy (C) (v2cademmob) [0-1]
g v2cademmob_2 = ((v2cademmob--3.274)/(4.157--3.274))*(1-0)+0

* Social group equality in respect for civil liberties (C) (v2clsocgrp) [0-1 and high --> less respect]
g v2clsocgrp_2 = ((v2clsocgrp-3.368)/(-3.142-3.368)*(1-0)+0)

* Political polarization [0-1]
gen v2cacamps_2 = ((v2cacamps--4)/(4.5--4))*(1-0)+0

* Political violence [0-1]
gen v2caviol_2 = ((v2caviol--4)/(4.5--4))*(1-0)+0

* Physical violence index [High --> less respect for physical integrity]
*gen v2x_clphy_2 =((v2x_clphy-1)/(0-1))*(1-0)+0

* Civil Liberties index  [High --> less respect for civil liberties]
gen v2x_civlib_2 =((v2x_civlib-1)/(0-1))*(1-0)+0

* Executive respects constitution [High --> less respect]
gen v2exrescon_2 =((v2exrescon-4)/(-3.5-4))*(1-0)+0

* Judicial constraints
g v2x_jucon_2 =((v2x_jucon-1)/(0-1))*(1-0)+0

* Legislative constrains
g v2xlg_legcon_2 =((v2xlg_legcon-1)/(0-1))*(1-0)+0

* Mobilization for autocracy [0-1]
gen v2caautmob_2 = ((v2caautmob--3)/(4.6--3))*(1-0)+0

* Coups (group coups and coup attempts)
recode e_pt_coup (2=1), g(e_pt_coup_2)

*** Natural log of oil pc
g e_total_oil_income_pc_1 = e_total_oil_income_pc+1
g oil_pc_ln = ln(e_total_oil_income_pc_1)

*** Recoding of NAVCO variables

* Non-violent campaign
g nonvio_camp_2 = nonvio_camp
replace nonvio_camp_2 = 0 if camp_goals==5

* Violent campaign
g vio_camp_2 = vio_camp
replace vio_camp_2 = 0 if camp_goals==5

* Repression of campaign
recode repression (.=0) if year >=1945 & year <=2006 & nonvio_camp!=.
gen repression_2 = ((repression-0)/(3-0))*(1-0)+0

* Alternative ethnic inequality measures
g ggini_2 = ((ggini-0)/(.6191273-0)*(1-0)+0)
g NHIxl_2 = ((NHIxl-1)/(6.773902-1)*(1-0)+0)
g CL_low1_overlap_2 = ((CL_low1_overlap-1)/(5.935248-1)*(1-0)+0)

* Ethnic diversity measures
g eth_fragm_2 = ((eth_fragm-0)/(.9302-0))*(1-0)+0
g rq_2 = ((rq-0)/(.239-0))*(1-0)+0
g cdiv_2 = ((cdiv-0)/(.7328356-0))*(1-0)+0

* Extrapolation of time-invariant measures
xfill eth_fragm_2, i(country_id)
xfill ef, i(country_id)
xfill rq_2, i(country_id)
xfill cdiv_2, i(country_id)


*** Time variables for probit estimations with decade FE
gen decade =.
recode decade (.=1) if year >= 1900 & year <= 1909 
recode decade (.=2) if year >= 1910 & year <= 1919 
recode decade (.=3) if year >= 1920 & year <= 1929 
recode decade (.=4) if year >= 1930 & year <= 1939 
recode decade (.=5) if year >= 1940 & year <= 1949 
recode decade (.=6) if year >= 1950 & year <= 1959 
recode decade (.=7) if year >= 1960 & year <= 1969 
recode decade (.=8) if year >= 1970 & year <= 1979 
recode decade (.=9) if year >= 1980 & year <= 1989 
recode decade (.=10) if year >= 1990 & year <= 1999 
recode decade (.=11) if year >= 2000 & year <= 2009 
recode decade (.=12) if year >= 2010 & year <= 2019 
recode decade (.=13) if year >= 2020 & year <= 2029



******************************************************************************************************************
******************************************** Analysis: Transitions ***********************************************
******************************************************************************************************************



*******************************************
*********** Table 1: Transitions **********
*******************************************

eststo: xtreg transition_lexical_5 L.SEI i.year if L.lexical_index_5==0 , fe cluster(country_id)
eststo: xtreg transition_lexical_5 L.SEI L.latent_gdppc_mean_log i.year if L.lexical_index_5==0 , fe cluster(country_id)
eststo: xtreg transition_lexical_5 L.SEI L.latent_gdppc_mean_log L.e_migdpgro L.oil_pc_ln L.region_lexical_5 L.v2svstterr i.year if L.lexical_index_5==0, fe cluster(country_id)

eststo: xtreg transition_boix L.SEI i.year if L.e_boix_regime==0 , fe cluster(country_id)
eststo: xtreg transition_boix L.SEI L.latent_gdppc_mean_log i.year if L.e_boix_regime==0 , fe cluster(country_id)
eststo: xtreg transition_boix L.SEI L.latent_gdppc_mean_log L.e_migdpgro L.oil_pc_ln L.region_bmr L.v2svstterr i.year if L.e_boix_regime==0, fe cluster(country_id)

estout,  cells(b(star fmt(%9.3f)) se(par) t(fmt(%9.2f)))   /// 
  stats(N N_g, fmt(%9.0f %9.0g) labels(Obs Countries)) starlevels(† 0.1 * 0.05  ** 0.01 *** 0.001) style(fixed) drop(*.year)
esttab using output_T1.rtf, b(3) se(3) se star(† 0.1 * 0.05 ** 0.01 *** 0.001) stats(N N_g, labels("Observations" "Countries") fmt(0 0)) drop(*.year)
eststo clear


*****************************************************
************ Figure 3: Transition mechanisms *********
*****************************************************

***** Step 1 ******

* New independent variable copies for coefplot figures
g SEI_1 = SEI
g SEI_2 = SEI
g SEI_3 = SEI
g SEI_4 = SEI
g SEI_5 = SEI
g SEI_6 = SEI
g SEI_7 = SEI
g SEI_8 = SEI


* Mass mobilization (C) (v2cagenmob)
eststo M1: xtreg v2cagenmob_2 L.SEI_1 L.latent_gdppc_mean_log i.year if L.lexical_index_5==0 , fe cluster(country_id)

* Mobilization for democracy (C) (v2cademmob)
eststo M2: xtreg v2cademmob_2 L.SEI_2 L.latent_gdppc_mean_log i.year if L.lexical_index_5==0 , fe cluster(country_id)

* Explicit and active regime opposition groups 
eststo M3: xtreg v2regoppgroupsact_6 L.SEI_3 L.latent_gdppc_mean_log i.year if L.lexical_index_5==0 , fe cluster(country_id)

* Non-violent campaign
eststo M4: xtreg nonvio_camp_2 L.SEI_4 L.latent_gdppc_mean_log i.year if L.lexical_index_5==0 , fe cluster(country_id)

* Violent campaign
eststo M5: xtreg vio_camp_2 L.SEI_5 L.latent_gdppc_mean_log i.year if L.lexical_index_5==0 , fe cluster(country_id)

*** Repression ***
eststo M6: xtreg v2x_civlib_2 L.SEI_6 L.latent_gdppc_mean_log i.year if L.lexical_index_5==0 , fe cluster(country_id)

*** Repression: Social group equality in respect for civil liberties (C) (v2clsocgrp)
eststo M7: xtreg v2clsocgrp_2 L.SEI_7 L.latent_gdppc_mean_log i.year if L.lexical_index_5==0 , fe cluster(country_id)

*** Repression of campaign
eststo M8: xtreg repression_2 L.SEI_8 L.latent_gdppc_mean_log i.year if L.lexical_index_5==0 , fe cluster(country_id)


coefplot (M1 M2 M3 M4 M5 M6 M7 M8), drop(_cons L.latent_gdppc_mean_log i.year *year) level(95) xline(0, lpattern(dash) lcolor(gs10%70)) ciopts(color(black) recast(rcap)) scheme(s2mono) graphregion(fcolor(white) lcolor(white) lwidth(tiny)) coeflabel(L.SEI_1 = "Mass mobilization" L.SEI_2 = "Pro-democratic mass mob." L.SEI_3 = "Ethnically-based regime-opp." L.SEI_4 = "Non-violent campaign onset " L.SEI_5 = "Violent campaign onset" L.SEI_6 = "Repression (general)" L.SEI_7 = "Repression (group-specific)" L.SEI_8 = "Repression of campaign") headings(L.SEI_1 = "{bf:Bottom-up: Mass mobilization}" L.SEI_6 = "{bf:Top-down: State Repression}") title("{bf:A}					Ethnic inequality and proxies for mechanisms", size(medsmall) justification(left) span pos(11)) subtitle(" ") msymbol(O) mcolor(black) name(fg3a)



***** Step 2 ******

* Mass mobilization (C) (v2cagenmob)
eststo M1: xtreg transition_lexical_5 L.v2cagenmob_2 L.latent_gdppc_mean_log i.year if L.lexical_index_5==0 , fe cluster(country_id)

* Mobilization for democracy (C) (v2cademmob)
eststo M2: xtreg transition_lexical_5 L.v2cademmob_2 L.latent_gdppc_mean_log i.year if L.lexical_index_5==0 , fe cluster(country_id)

* Explicit and active regime opposition groups 
eststo M3: xtreg transition_lexical_5 L.v2regoppgroupsact_6 L.latent_gdppc_mean_log i.year if L.lexical_index_5==0 , fe cluster(country_id)

* Non-violent campaign
eststo M4: xtreg transition_lexical_5 L.nonvio_camp_2 L.latent_gdppc_mean_log i.year if L.lexical_index_5==0 , fe cluster(country_id)

* Violent campaign
eststo M5: xtreg transition_lexical_5 L.vio_camp_2 L.latent_gdppc_mean_log i.year if L.lexical_index_5==0 , fe cluster(country_id)

*** Repression ***
eststo M6: xtreg transition_lexical_5 L.v2x_civlib_2 L.latent_gdppc_mean_log i.year if L.lexical_index_5==0 , fe cluster(country_id)

*** Repression: Social group equality in respect for civil liberties (C) (v2clsocgrp)
eststo M7: xtreg transition_lexical_5 L.v2clsocgrp_2 L.latent_gdppc_mean_log i.year if L.lexical_index_5==0 , fe cluster(country_id)

*** Repression of campaign
eststo M8: xtreg transition_lexical_5 L.repression_2 L.latent_gdppc_mean_log i.year if L.lexical_index_5==0 , fe cluster(country_id)



coefplot (M1 M2 M3 M4 M5 M6 M7 M8), drop(_cons L.latent_gdppc_mean_log i.year *year) level(95) xline(0, lpattern(dash) lcolor(gs10%70)) ciopts(color(black) recast(rcap)) scheme(s2mono) graphregion(fcolor(white) lcolor(white) lwidth(tiny)) coeflabel(L.v2cagenmob_2 = "Mass mobilization" L.v2cademmob_2 = "Pro-democratic mass mob." L.v2regoppgroupsact_6  = "Ethnically-based regime-opp." L.nonvio_camp_2 = "Non-violent campaign onset" L.vio_camp_2 = "Violent campaign onset"  L.v2x_civlib_2 = "Repression (general)" L.v2clsocgrp_2 = "Repression (group-specific)" L.repression_2 = "Repression of campaign") headings(L.v2cagenmob_2 = "{bf:Bottom-up: Mass mobilization}" L.v2x_civlib_2 = "{bf:Top-down: State Repression}") title("{bf:B}					Proxies for mechanisms and democratic transitions", size(medsmall) justification(left) span pos(11)) subtitle(" ") msymbol(O) mcolor(black) name(fg3b)

graph combine fg3a fg3b, rows(1) scheme(s2mono) graphregion(fcolor(white) lcolor(black) lwidth(tiny)) name(fg3)
graph display fg3, xsize(2) ysize(1)
graph export "fg3.tif", width(8000) replace
graph export "fg3.pdf", replace

eststo clear

******************************************************************************************************************
******************************************** Analysis: Breakdowns ***********************************************
******************************************************************************************************************

*****************************************************
****************** Table 2: Breakdowns **************
*****************************************************

* Lexical
eststo: xtreg breakdown_lexical_5 L.SEI i.year if L.lexical_index_5==1 , fe cluster(country_id)
eststo: xtreg breakdown_lexical_5 L.SEI L.latent_gdppc_mean_log i.year if L.lexical_index_5==1 , fe cluster(country_id)
eststo: xtreg breakdown_lexical_5 L.SEI L.latent_gdppc_mean_log L.e_migdpgro L.oil_pc_ln L.region_lexical_5 L.v2svstterr i.year if L.lexical_index_5==1, cluster(country_id) fe

* BMR
eststo: xtreg breakdown_boix L.SEI	i.year if L.e_boix_regime==1 , fe cluster(country_id)
eststo: xtreg breakdown_boix L.SEI L.latent_gdppc_mean_log i.year if L.e_boix_regime==1 , fe cluster(country_id)
eststo: xtreg breakdown_boix L.SEI L.latent_gdppc_mean_log L.e_migdpgro L.oil_pc_ln L.region_bmr L.v2svstterr i.year if L.e_boix_regime==1, cluster(country_id) fe

estout,  cells(b(star fmt(%9.3f)) se(par) t(fmt(%9.2f)))   /// 
  stats(N N_g, fmt(%9.0f %9.0g) labels(Obs Countries)) starlevels(† 0.1 * 0.05  ** 0.01 *** 0.001) style(fixed) drop(*.year)
esttab using output_T2.rtf, b(3) se(3) se star(† 0.1 * 0.05 ** 0.01 *** 0.001) stats(N N_g, labels("Observations" "Countries") fmt(0 0)) drop(*.year)
eststo clear

*** Interpretation of coefficient

* Calculate standard deviation within countries and take global average
bys country_id: egen within_country = sd(SEI)
egen within_country_avg = mean(within_country)
di 0.162*.1020224
di 0.172*.1020224 


*****************************************************
************ Figure 4: Breakdown Mechanisms *********
*****************************************************

***** Step 1 ******

* Political polarization
eststo M1: xtreg v2cacamps_2 L.SEI_1 L.latent_gdppc_mean_log i.year if L.lexical_index_5==1, fe cluster(country_id)

* Mobilization for autocracy
eststo M2: xtreg v2caautmob_2 L.SEI_2 L.latent_gdppc_mean_log  i.year if L.lexical_index_5==1, fe cluster(country_id)

* Ethnically-based regime opposition
eststo M3: xtreg v2regoppgroupsact_6 L.SEI_3 L.latent_gdppc_mean_log  i.year if L.lexical_index_5==1, fe cluster(country_id)

* Political violence
eststo M4: xtreg v2caviol_2 L.SEI_4 L.latent_gdppc_mean_log i.year if L.lexical_index_5==1, fe cluster(country_id)

* Violent campaign onset
eststo M5: xtreg vio_camp_2 L.SEI_5 L.latent_gdppc_mean_log i.year if L.lexical_index_5==1, fe cluster(country_id)

* Judicial constraints
eststo M6: xtreg v2x_jucon_2 L.SEI_6 L.latent_gdppc_mean_log  i.year if L.lexical_index_5==1, fe cluster(country_id)

* Legislative constraints
eststo M7: xtreg v2xlg_legcon_2 L.SEI_7 L.latent_gdppc_mean_log  i.year if L.lexical_index_5==1, fe cluster(country_id)

* Coups
eststo M8: xtreg e_pt_coup_2 L.SEI_8 L.latent_gdppc_mean_log  i.year if L.lexical_index_5==1, fe cluster(country_id)

coefplot (M1 M2 M3 M4 M5 M6 M7 M8), drop(_cons L.latent_gdppc_mean_log i.year *year) level(95) xline(0, lpattern(dash) lcolor(gs10%70)) ciopts(color(black) recast(rcap)) scheme(s2mono) graphregion(fcolor(white) lcolor(white)) coeflabel(L.SEI_1 = "Political polarization" L.SEI_2 = "Mobiliz. for autocracy" L.SEI_3 = "Ethnic regime opp." L.SEI_4 = "Political violence"  L.SEI_5 = "Violent campaign onset" L.SEI_6 = "Power concentration (jud.)" L.SEI_7 = "Power concentration (leg.)"  L.SEI_8 = "Coups attempts") headings(L.SEI_1 = "{bf:Political polarization}" L.SEI_2 = "{bf:Mass anti-dem. behav.}" L.SEI_6 = "{bf:Elite anti-dem. behav.}") title("{bf:A}				Ethnic inequality and proxies for mechanisms", size(medsmall) justification(left) span pos(11)) subtitle(" ") msymbol(O) mcolor(black) name(fg4a)


***** Step 2 ******

* Political polarization
eststo M10: xtreg breakdown_lexical_5 L.v2cacamps_2 L.latent_gdppc_mean_log i.year if L.lexical_index_5==1, fe cluster(country_id)

* Mobilization for autocracy
eststo M11: xtreg breakdown_lexical_5 L.v2caautmob_2 L.latent_gdppc_mean_log i.year if L.lexical_index_5==1, fe cluster(country_id)

* Ethnically-based regime opposition
eststo M12: xtreg breakdown_lexical_5 L.v2regoppgroupsact_6 L.latent_gdppc_mean_log i.year if L.lexical_index_5==1, fe cluster(country_id)

* Political violence 
eststo M13: xtreg breakdown_lexical_5 L.v2caviol_2 L.latent_gdppc_mean_log i.year if L.lexical_index_5==1, fe cluster(country_id)

* Violent campaign onset
eststo M14: xtreg breakdown_lexical_5 L.vio_camp_2 L.latent_gdppc_mean_log i.year if L.lexical_index_5==1, fe cluster(country_id)

* Judicial constraints
eststo M15: xtreg breakdown_lexical_5 L.v2x_jucon_2 L.latent_gdppc_mean_log i.year if L.lexical_index_5==1, fe cluster(country_id)

* Legislative constraints
eststo M16: xtreg breakdown_lexical_5 L.v2xlg_legcon_2 L.latent_gdppc_mean_log i.year if L.lexical_index_5==1, fe cluster(country_id)

* Coups
eststo M17: xtreg breakdown_lexical_5 e_pt_coup_2 L.latent_gdppc_mean_log i.year if L.lexical_index_5==1, fe cluster(country_id)

coefplot (M10 M11 M12 M13 M14 M15 M16 M17), drop(_cons L.latent_gdppc_mean_log i.year *year) level(95) xline(0, lpattern(dash) lcolor(gs10%70)) ciopts(color(black) recast(rcap)) scheme(s2mono) graphregion(fcolor(white) lcolor(white)) coeflabel(L.v2cacamps_2 = "Political polarization"  L.v2caautmob_2 = "Mobiliz. for autocracy" L.v2regoppgroupsact_6 ="Ethnic regime opp." L.v2caviol_2 = "Political violence" L.vio_camp_2 = "Violent campaign onset"  L.v2x_jucon_2 = "Power concentration (jud.)" L.v2xlg_legcon_2 = "Power concentration (leg.)" e_pt_coup_2  = "Coups attempts") xlabel(0(0.1)0.6) headings(L.v2cacamps_2 = "{bf:Political polarization}" L.v2caautmob_2 = "{bf:Mass anti-dem. behav.}" L.v2x_jucon_2 = "{bf:Elite anti-dem. behav.}") title("{bf:B}				Proxies for mechanisms and democratic breakdown", size(medsmall) justification(left) span pos(11))  msymbol(O) mcolor(black) subtitle(" ") msymbol(O) mcolor(black) name(fg4b)

graph combine fg4a fg4b, rows(1) scheme(s2mono) graphregion(fcolor(white) lcolor(black) lwidth(tiny)) name(fg4)
graph display fg4, xsize(2) ysize(1)
graph export "fg4.tif", width(8000) replace
graph export "fg4.pdf", replace
eststo clear

**************************************************************************
*************** Figure 5: Alternative Ethnic Inequality Indices **********
**************************************************************************

*** Transitions (baseline models)
eststo M11: xtreg transition_lexical_5 L.SEI L.latent_gdppc_mean_log i.year if L.lexical_index_5==0 , fe cluster(country_id)
eststo M12: xtreg transition_lexical_5 L.ggini_2 L.latent_gdppc_mean_log i.year if L.lexical_index_5==0 , fe cluster(country_id)
eststo M13: reg transition_lexical_5 L.NHIxl_2 L.latent_gdppc_mean_log i.decade if L.lexical_index_5==0, cluster(country_id)
eststo M14: reg transition_lexical_5 L.CL_low1_overlap_2 L.latent_gdppc_mean_log i.decade if L.lexical_index_5==0, cluster(country_id)

coefplot (M11, label(Coppedge et al.)) (M12, label(Omoeva et al.)) (M13, label(Cederman et al. 2013)) (M14, label(Cederman et al. 2015)), drop(_cons L.latent_gdppc_mean_log i.year i.decade *year *decade) level(95) xline(0, lpattern(dash) lcolor(gs10%70)) ciopts(color(black) recast(rcap)) scheme(s2mono) graphregion(fcolor(white) lcolor(white)) coeflabel(L.SEI = "Coppedge et al. (2021)" L.ggini_2 = "Omoeva et al. (2018)" L.NHIxl_2 = "Cederman et al. (2013)"  L.CL_low1_overlap_2 = "Cederman et al. (2015)", labsize(medsmall)) title("{bf:A}						Ethnic inequality and democratic transitions", size(medsmall) justification(left) span pos(11)) subtitle(" ") msymbol(O) mcolor(black)  legend(off) xlabel(, nogrid) ylabel(, nogrid) offset(0) grid(none) name(fg5a)


*** Breakdown (baseline models)
eststo M21: xtreg breakdown_lexical_5 L.SEI L.latent_gdppc_mean_log i.year if L.lexical_index_5==1 , fe cluster(country_id)
eststo M22: xtreg breakdown_lexical_5 L.ggini_2 L.latent_gdppc_mean_log i.year if L.lexical_index_5==1 , fe cluster(country_id)
eststo M23: reg breakdown_lexical_5 L.NHIxl_2 L.latent_gdppc_mean_log i.decade if L.lexical_index_5==1, cluster(country_id)
eststo M24: reg breakdown_lexical_5 L.CL_low1_overlap_2 L.latent_gdppc_mean_log i.decade if L.lexical_index_5==1, cluster(country_id)

coefplot (M21, label(Coppedge et al.)) (M22, label(Omoeva et al.)) (M23, label(Cederman et al. 2013)) (M24, label(Cederman et al. 2015)), drop(_cons L.latent_gdppc_mean_log i.year i.decade *year *decade) level(95) xline(0, lpattern(dash) lcolor(gs10%70)) ciopts(color(black) recast(rcap)) scheme(s2mono) graphregion(fcolor(white) lcolor(white)) coeflabel(L.SEI = "Coppedge et al. (2021)" L.ggini_2 = "Omoeva et al. (2018)" L.NHIxl_2 = "Cederman et al. (2013)"  L.CL_low1_overlap_2 = "Cederman et al. (2015)", labsize(medsmall)) title("{bf:B}					Ethnic inequality and democratic breakdowns", size(medsmall) justification(left) span pos(11)) subtitle(" ") msymbol(O) mcolor(black) legend(off) xlabel(, nogrid) ylabel(, nogrid) offset(0) grid(none) name(fg5b)

graph combine fg5a fg5b, rows(1) scheme(s2mono) graphregion(fcolor(white) lcolor(black) lwidth(tiny)) name(fg5)
graph display fg5, xsize(2) ysize(1)
graph export "fg5.tif", width(8000) replace
graph export "fg5.pdf", replace
eststo clear

*************************************************************************************
************ Figure 6: Comparing with Non-Ethnic Inequality  ***********************
*************************************************************************************

* Rescale 0-1
gen gini_disp_2 = ((gini_disp-17.5)/(67.1-17.5))*(1-0)+0
gen v2peapsecon_2 = ((v2peapsecon--3.1)/(3.7--3.1))*(1-0)+0

eststo m1: xtreg breakdown_lexical_5 L.SEI L.latent_gdppc_mean_log i.year if L.lexical_index_5==1 , fe cluster(country_id)
eststo m2: xtreg breakdown_lexical_5 L.gini_disp_2 L.latent_gdppc_mean_log i.year if L.lexical_index_5==1 , fe cluster(country_id)
eststo m3: xtreg breakdown_lexical_5 L.v2peapsecon_2 L.latent_gdppc_mean_log i.year if L.lexical_index_5==1 , fe cluster(country_id)

coefplot (m1, label(Ethnic inequality)) (m2, label(Non-ethnic, income)) (m3, label(Non-ethnic, pub. serv.)), drop(_cons L.latent_gdppc_mean_log i.year *year *decade) level(95) xline(0, lpattern(dash) lcolor(gs10%70)) ciopts(color(black) recast(rcap)) scheme(s2mono) graphregion(fcolor(white) lcolor(black) lwidth(tiny)) coeflabel(L.SEI = "V-Dem, ethnic inequality" L.gini_disp_2 = "SWIID, income inequality" L.v2peapsecon_2 = "V-Dem, socio-eco. inequality", labsize(medsmall)) msymbol(O) mcolor(black) legend(off) xlabel(, nogrid) ylabel(, nogrid) offset(0) grid(none) name(fg6)

graph export "fg6.tif", width(8000) replace
graph export "fg6.pdf", replace
eststo clear


*********************************************************************************************
*********************************************************************************************
************************************* Appendix **********************************************
*********************************************************************************************
*********************************************************************************************


*****************************************************************
************** Table A1: Descriptive statistics *****************
*****************************************************************

* Democratic transitions
sum transition_lexical_4 transition_lexical_5 transition_lexical_6 transition_boix if year >= 1900

* Democratic breakdowns
sum breakdown_lexical_4 breakdown_lexical_5 breakdown_lexical_6 breakdown_boix if year >= 1900

* Ethnic inequality
sum SEI ggini NHIxl CL_low1_overlap if year >= 1900

* Controls
sum latent_gdppc_mean_log e_migdpgro oil_pc_ln region_lexical_4 region_lexical_5 region_lexical_6 region_bmr v2svstterr if year >= 1900

* Mechanism test 1
sum v2cagenmob_2 v2cademmob_2 v2regoppgroupsact_6 v2x_civlib_2 v2clsocgrp_2 nonvio_camp_2 vio_camp_2 repression_2 if year >= 1900

* Mechanism test 2
sum v2cacamps_2 v2caautmob_2 v2caviol_2 v2x_jucon_2 v2xlg_legcon_2 e_pt_coup_2 if year >= 1900

* Implication test
sum v2peapsecon_2  gini_disp_2 if year >= 1900
sum eth_fragm_2 ef cdiv_2 rq_2 if year >= 1960


*****************************************************************
***************** Figure A1: Map *********************************
*****************************************************************

spmap SEI using "worldcoor" if year==2000, id(map_id) fcolor(Blues2) osize(vvthin vvthin vvthin vvthin) ndsize(vvthin) clmethod(quantile) leg(off) graphregion(lcolor(black) lwidth(tiny)) name(fgA1)
graph export "fgA1.pdf", replace

*****************************************************************
***************** Figure A2-A7: Country graphs ******************
*****************************************************************

* Not include missing values
g country_name_2 = country_name
replace country_name_2 ="" if SEI==.

* Split SSA into two graphs due to high number of countries
g SSA1 = 0
recode SSA1 (0=1) if country_name == "Angola" 
recode SSA1 (0=1) if country_name == "Benin" 
recode SSA1 (0=1) if country_name == "Botswana" 
recode SSA1 (0=1) if country_name == "Burkina Faso" 
recode SSA1 (0=1) if country_name == "Burundi" 
recode SSA1 (0=1) if country_name == "Cameroon" 
recode SSA1 (0=1) if country_name == "Cape Verde" 
recode SSA1 (0=1) if country_name == "Central African Republic" 
recode SSA1 (0=1) if country_name == "Chad" 
recode SSA1 (0=1) if country_name == "Comoros" 
recode SSA1 (0=1) if country_name == "Congo Brazaville"
recode SSA1 (0=1) if country_name == "Congo, Democratic Republic"
recode SSA1 (0=1) if country_name == "Code d'Ivoire"
recode SSA1 (0=1) if country_name == "Djibouti"
recode SSA1 (0=1) if country_name == "Equitorial Guinea"
recode SSA1 (0=1) if country_name == "Eritrea"
recode SSA1 (0=1) if country_name == "Ethiopia"
recode SSA1 (0=1) if country_name == "Gabon"
recode SSA1 (0=1) if country_name == "Gambia"
recode SSA1 (0=1) if country_name == "Ghana"
recode SSA1 (0=1) if country_name == "Guinea"
recode SSA1 (0=1) if country_name == "Guinea-Bissau"
recode SSA1 (0=1) if country_name == "Kenya"
recode SSA1 (0=1) if country_name == "Lesotho"

* A2
xtline SEI  if e_regionpol_6C==1 & year>=1900 & year <=2025, i(country_name_2) t(year) scheme(plotplain) xlabel(1900 "1900" 1925 "1925" 1950 "1950" 1975 "1975" 2000 "2000" 2025 "2025") ytitle(Ethnic inequality) xtitle(Year)  byopts(note("")) name(fgA2)
graph export "fgA2.pdf", replace

* A3
xtline SEI  if e_regionpol_6C==2 & year>=1900 & year <=2025, i(country_name_2) t(year) scheme(plotplain) xlabel(1900 "1900" 1925 "1925" 1950 "1950" 1975 "1975" 2000 "2000" 2025 "2025") ytitle(Ethnic inequality) xtitle(Year)  byopts(note("")) name(fgA3)
graph export "fgA3.pdf", replace

* A4 
xtline SEI  if e_regionpol_6C==3 & year>=1900 & year <=2025, i(country_name_2) t(year) scheme(plotplain) xlabel(1900 "1900" 1925 "1925" 1950 "1950" 1975 "1975" 2000 "2000" 2025 "2025") ytitle(Ethnic inequality) xtitle(Year)  byopts(note("")) name(fgA4)
graph export "fgA4.pdf", replace

* A5 (panel A)
xtline SEI  if e_regionpol_6C==4 & SSA==1 & year>=1900 & year <=2025, i(country_name_2) t(year) scheme(plotplain) xlabel(1900 "1900" 1925 "1925" 1950 "1950" 1975 "1975" 2000 "2000" 2025 "2025") ytitle(Ethnic inequality) xtitle(Year)  byopts(note("")) name(fgA5a)
graph export "fgA5a.pdf", replace

* A5 (panel B)
xtline SEI  if e_regionpol_6C==4 & SSA!=1 & year>=1900 & year <=2025, i(country_name_2) t(year) scheme(plotplain) xlabel(1900 "1900" 1925 "1925" 1950 "1950" 1975 "1975" 2000 "2000" 2025 "2025") ytitle(Ethnic inequality) xtitle(Year)  byopts(note("")) name(fgA5b)
graph export "fgA5b.pdf", replace

* A6
xtline SEI  if e_regionpol_6C==5 & year>=1900 & year <=2025, i(country_name_2) t(year) scheme(plotplain) xlabel(1900 "1900" 1925 "1925" 1950 "1950" 1975 "1975" 2000 "2000" 2025 "2025") ytitle(Ethnic inequality) xtitle(Year)  byopts(note("")) name(fgA6)
graph export "fgA6.pdf", replace

* A7
xtline SEI  if e_regionpol_6C==6 & year>=1900 & year <=2025, i(country_name_2) t(year) scheme(plotplain) xlabel(1900 "1900" 1925 "1925" 1950 "1950" 1975 "1975" 2000 "2000" 2025 "2025") ytitle(Ethnic inequality) xtitle(Year)  byopts(note("")) name(fgA7)
graph export "fgA7.pdf", replace



**************************************************************************
*************************** Table A6: BTI ********************************
**************************************************************************

eststo: reg identity L.SEI L.latent_gdppc_mean_log i.e_regionpol_6C if L.lexical_index_5==0, cluster(country_id)
eststo: reg equal L.SEI L.latent_gdppc_mean_log i.e_regionpol_6C if L.lexical_index_5==0, cluster(country_id)
eststo: reg conflict_intens L.SEI L.latent_gdppc_mean_log i.e_regionpol_6C if L.lexical_index_5==0, cluster(country_id)
eststo: reg cleavage L.SEI L.latent_gdppc_mean_log i.e_regionpol_6C if L.lexical_index_5==0, cluster(country_id)

eststo: reg identity L.SEI L.latent_gdppc_mean_log i.e_regionpol_6C if L.lexical_index_5==1, cluster(country_id)
eststo: reg equal L.SEI L.latent_gdppc_mean_log i.e_regionpol_6C if L.lexical_index_5==1, cluster(country_id)
eststo: reg conflict_intens L.SEI L.latent_gdppc_mean_log i.e_regionpol_6C if L.lexical_index_5==1, cluster(country_id)
eststo: reg cleavage L.SEI L.latent_gdppc_mean_log i.e_regionpol_6C if L.lexical_index_5==1, cluster(country_id)

estout,  cells(b(star fmt(%9.3f)) se(par) t(fmt(%9.2f)))   /// 
  stats(N N_g, fmt(%9.0f %9.0g) labels(Obs Countries)) starlevels(† 0.1 * 0.05  ** 0.01 *** 0.001) style(fixed)
esttab using output_TA6.rtf, b(3) se(3) se star(† 0.1 * 0.05 ** 0.01 *** 0.001) stats(N N_g, labels("Observations" "Countries") fmt(0 0))
eststo clear


***** For additional analyses using group-level and individual-level data, see bottom of do-file *****


**************************************************************************
************************* Formal mediation analysis *********************
**************************************************************************

*** Table A7: Mediators between Ethnic Inequality and Democratic Transitions ***

* Prepare variables for two-way fixed effects by demeaning them
qui reg SEI i.year i.country_id
predict SEI_fe,r

qui reg breakdown_lexical_5 i.year i.country_id
predict breakdown_lexical_5_fe,r

qui reg transition_lexical_5 i.year i.country_id
predict transition_lexical_5_fe,r

qui reg latent_gdppc_mean_log i.year i.country_id
predict latent_gdppc_mean_log_fe,r

qui reg v2cagenmob_2 i.year i.country_id
predict v2cagenmob_2_fe,r

qui reg v2cademmob_2 i.year i.country_id
predict v2cademmob_2_fe,r

qui reg v2regoppgroupsact_6 i.year i.country_id
predict v2regoppgroupsact_6_fe,r

qui reg nonvio_camp_2 i.year i.country_id
predict nonvio_camp_2_fe,r

qui reg vio_camp_2 i.year i.country_id
predict vio_camp_2_fe,r

qui reg v2x_civlib_2 i.year i.country_id
predict v2x_civlib_2_fe,r

qui reg v2clsocgrp_2 i.year i.country_id
predict v2clsocgrp_2_fe,r

qui reg repression_2 i.year i.country_id
predict repression_2_fe,r

* Dichotmous treatment variable
g SEI_fe_bin =.
recode SEI_fe_bin (.=1) if SEI_fe >= .0012064 & SEI_fe!=.
recode SEI_fe_bin (.=0) if SEI_fe < .0012064 & SEI_fe!=.


* Mass mobilization (C) (v2cagenmob)
medeff (regress v2cagenmob_2_fe SEI_fe_bin latent_gdppc_mean_log_fe) (regress transition_lexical_5_fe SEI_fe_bin v2cagenmob_2_fe latent_gdppc_mean_log_fe) if L.lexical_index_5==0 , treat(SEI_fe_bin) mediate(v2cagenmob_2_fe) sims(1000) seed(1) vce(cluster country_id)

* Mobilization for democracy (C) (v2cademmob)
medeff (regress v2cademmob_2_fe SEI_fe_bin latent_gdppc_mean_log_fe) (regress transition_lexical_5_fe SEI_fe_bin v2cademmob_2_fe latent_gdppc_mean_log_fe) if L.lexical_index_5==0 , treat(SEI_fe_bin) mediate(v2cademmob_2_fe) sims(1000) seed(1) vce(cluster country_id)

* Explicit and active regime opposition groups 
medeff (regress v2regoppgroupsact_6_fe SEI_fe_bin latent_gdppc_mean_log_fe) (regress transition_lexical_5_fe SEI_fe_bin v2regoppgroupsact_6_fe latent_gdppc_mean_log_fe) if L.lexical_index_5==0 , treat(SEI_fe_bin) mediate(v2regoppgroupsact_6_fe) sims(1000) seed(1) vce(cluster country_id)

* Non-violent campaign
medeff (regress nonvio_camp_2_fe SEI_fe_bin latent_gdppc_mean_log_fe) (regress transition_lexical_5_fe SEI_fe_bin nonvio_camp_2_fe latent_gdppc_mean_log_fe) if L.lexical_index_5==0 , treat(SEI_fe_bin) mediate(nonvio_camp_2_fe) sims(1000) seed(1) vce(cluster country_id)

* Violent campaign
medeff (regress vio_camp_2_fe SEI_fe_bin latent_gdppc_mean_log_fe) (regress transition_lexical_5_fe SEI_fe_bin vio_camp_2_fe latent_gdppc_mean_log_fe) if L.lexical_index_5==0 , treat(SEI_fe_bin) mediate(vio_camp_2_fe) sims(1000) seed(1) vce(cluster country_id)

*** Repression ***
medeff (regress v2x_civlib_2_fe SEI_fe_bin latent_gdppc_mean_log_fe) (regress transition_lexical_5_fe SEI_fe_bin v2x_civlib_2_fe latent_gdppc_mean_log_fe) if L.lexical_index_5==0 , treat(SEI_fe_bin) mediate(v2x_civlib_2_fe) sims(1000) seed(1) vce(cluster country_id)

*** Repression: Social group equality in respect for civil liberties (C) (v2clsocgrp)
medeff (regress v2clsocgrp_2_fe SEI_fe_bin latent_gdppc_mean_log_fe) (regress transition_lexical_5_fe SEI_fe_bin v2clsocgrp_2_fe latent_gdppc_mean_log_fe) if L.lexical_index_5==0 , treat(SEI_fe_bin) mediate(v2clsocgrp_2_fe) sims(1000) seed(1) vce(cluster country_id)

*** Repression of campaign
medeff (regress repression_2_fe SEI_fe_bin latent_gdppc_mean_log_fe) (regress transition_lexical_5_fe SEI_fe_bin repression_2_fe latent_gdppc_mean_log_fe) if L.lexical_index_5==0 , treat(SEI_fe_bin) mediate(repression_2_fe) sims(1000) seed(1) vce(cluster country_id)



*** Table A8: Mediators between Ethnic Inequality and Democratic Breakdowns ***

qui reg v2cacamps_2 i.year i.country_id
predict v2cacamps_2_fe,r

qui reg v2caautmob_2 i.year i.country_id
predict v2caautmob_2_fe,r

qui reg v2caviol_2  i.year i.country_id
predict v2caviol_2_fe,r

qui reg v2x_jucon_2 i.year i.country_id
predict v2x_jucon_2_fe,r

qui reg v2xlg_legcon_2 i.year i.country_id
predict v2xlg_legcon_2_fe,r

qui reg e_pt_coup_2 i.year i.country_id
predict e_pt_coup_2_fe,r



* Political polarization
medeff (regress v2cacamps_2_fe SEI_fe_bin latent_gdppc_mean_log_fe) (regress breakdown_lexical_5 SEI_fe_bin v2cacamps_2_fe latent_gdppc_mean_log_fe) if L.lexical_index_5==1, treat(SEI_fe_bin) mediate(v2cacamps_2_fe) sims(1000) seed(1) vce(cluster country_id)

* Mobilization for autocracy
medeff (regress v2caautmob_2_fe SEI_fe_bin latent_gdppc_mean_log_fe) (regress breakdown_lexical_5 SEI_fe_bin v2caautmob_2_fe latent_gdppc_mean_log_fe) if L.lexical_index_5==1, treat(SEI_fe_bin) mediate(v2caautmob_2_fe) sims(1000) seed(1) vce(cluster country_id)

* Ethnically-based regime opposition
medeff (regress v2regoppgroupsact_6_fe SEI_fe_bin latent_gdppc_mean_log_fe) (regress breakdown_lexical_5 SEI_fe_bin v2regoppgroupsact_6_fe latent_gdppc_mean_log_fe) if L.lexical_index_5==1, treat(SEI_fe_bin) mediate(v2regoppgroupsact_6_fe) sims(1000) seed(1) vce(cluster country_id)

* Political violence
medeff (regress v2caviol_2_fe SEI_fe_bin latent_gdppc_mean_log_fe) (regress breakdown_lexical_5 SEI_fe_bin v2caviol_2_fe latent_gdppc_mean_log_fe) if L.lexical_index_5==1, treat(SEI_fe_bin) mediate(v2caviol_2_fe) sims(1000) seed(1) vce(cluster country_id)

* Violent campaign onset
medeff (regress vio_camp_2_fe SEI_fe_bin latent_gdppc_mean_log_fe) (regress breakdown_lexical_5 SEI_fe_bin vio_camp_2_fe latent_gdppc_mean_log_fe) if L.lexical_index_5==1, treat(SEI_fe_bin) mediate(vio_camp_2_fe) sims(1000) seed(1) vce(cluster country_id)

* Judicial constraints
medeff (regress v2x_jucon_2_fe SEI_fe_bin latent_gdppc_mean_log_fe) (regress breakdown_lexical_5 SEI_fe_bin v2x_jucon_2_fe latent_gdppc_mean_log_fe) if L.lexical_index_5==1, treat(SEI_fe_bin) mediate(v2x_jucon_2_fe) sims(1000) seed(1) vce(cluster country_id)

* Legislative constraints
medeff (regress v2xlg_legcon_2_fe SEI_fe_bin latent_gdppc_mean_log_fe) (regress breakdown_lexical_5 SEI_fe_bin v2xlg_legcon_2_fe latent_gdppc_mean_log_fe) if L.lexical_index_5==1, treat(SEI_fe_bin) mediate(v2xlg_legcon_2_fe) sims(1000) seed(1) vce(cluster country_id)

* Coups
medeff (regress e_pt_coup_2_fe SEI_fe_bin latent_gdppc_mean_log_fe) (regress breakdown_lexical_5 SEI_fe_bin e_pt_coup_2_fe latent_gdppc_mean_log_fe) if L.lexical_index_5==1, treat(SEI_fe_bin) mediate(e_pt_coup_2_fe) sims(1000) seed(1) vce(cluster country_id)



***************************************************************************
************ Figure A8: Ethnic diversity measures *************************
***************************************************************************
eststo m1: xtreg breakdown_lexical_5 L.SEI L.latent_gdppc_mean_log i.year if L.lexical_index_5==1, fe cluster(country_id)
eststo m2: reg breakdown_lexical_5 L.eth_fragm_2 L.latent_gdppc_mean_log i.decade if L.lexical_index_5==1 & year >=1960, cluster(country_id)
eststo m3: reg breakdown_lexical_5 L.ef L.latent_gdppc_mean_log i.decade if L.lexical_index_5==1 & year >=1960 , cluster(country_id)
eststo m4: reg breakdown_lexical_5 L.cdiv_2 L.latent_gdppc_mean_log i.decade if L.lexical_index_5==1 & year >=1960 , cluster(country_id)
eststo m5: reg breakdown_lexical_5 L.rq_2 L.latent_gdppc_mean_log i.decade if L.lexical_index_5==1  & year >=1960 , cluster(country_id)

coefplot (m1) (m2) (m3) (m4) (m5), drop(_cons L.latent_gdppc_mean_log i.year *year *decade) level(95) xline(0, lpattern(dash) lcolor(gs10%70)) ciopts(color(black) recast(rcap)) scheme(s2mono) graphregion(fcolor(white) lcolor(black) lwidth(tiny)) coeflabel(L.SEI = "Ethnic ineq (V-Dem)" L.eth_fragm_2 = "Ethnic fract. (Alesina et al.)" L.ef = "Ethnic fract. (Fearon)" L.cdiv_2 = "Cultural fract. (Fearon)"  L.rq_2 = "Polarization (M & R-Q)", labsize(medsmall)) msymbol(O) mcolor(black) legend(off) xlabel(, nogrid) ylabel(, nogrid) offset(0) grid(none) name(fgA8)

graph export "fgA8.pdf", replace
eststo clear

**************************************************************************
*************** Table A9: Inequality at time of transition ******************
**************************************************************************

gen pre_demo_SEI_0 = SEI if lexical_index_5==0 & F.lexical_index_5==1
replace pre_demo_SEI_0 = L.pre_demo_SEI_0 if lexical_index_5!=0
replace pre_demo_SEI_0 = SEI if pre_demo_SEI_0 == .

eststo: xtreg breakdown_lexical_5 L.SEI pre_demo_SEI_0 i.year if L.lexical_index_5==1 , fe cluster(country_id)
eststo: xtreg breakdown_lexical_5 L.SEI pre_demo_SEI_0 L.latent_gdppc_mean_log i.year if L.lexical_index_5==1 , fe cluster(country_id)
eststo: xtreg breakdown_lexical_5 L.SEI pre_demo_SEI_0 L.latent_gdppc_mean_log L.e_migdpgro L.oil_pc_ln L.region_lexical_5 L.v2svstterr i.year if L.lexical_index_5==1, cluster(country_id) fe

estout,  cells(b(star fmt(%9.3f)) se(par) t(fmt(%9.2f)))   /// 
  stats(N N_g, fmt(%9.0f %9.0g) labels(Obs Countries)) starlevels(† 0.1 * 0.05  ** 0.01 *** 0.001) style(fixed) drop(*.year)
esttab using output_TA9.rtf, b(3) se(3) se star(† 0.1 * 0.05 ** 0.01 *** 0.001) stats(N N_g, labels("Observations" "Countries") fmt(0 0)) drop(*.year)
eststo clear


*************************************************************************************
******* Table A10: Controlling for public services by socio-economic status  *********
*************************************************************************************

eststo: xtreg transition_lexical_5 L.SEI  L.v2peapsecon_2 i.year if L.lexical_index_5==0 , fe cluster(country_id)
eststo: xtreg transition_lexical_5 L.SEI  L.v2peapsecon_2 L.latent_gdppc_mean_log i.year if L.lexical_index_5==0 , fe cluster(country_id)
eststo: xtreg transition_lexical_5 L.SEI  L.v2peapsecon_2 L.latent_gdppc_mean_log L.e_migdpgro L.oil_pc_ln L.region_lexical_5 L.v2svstterr i.year if L.lexical_index_5==0, fe cluster(country_id)

eststo: xtreg breakdown_lexical_5 L.SEI  L.v2peapsecon_2 i.year if L.lexical_index_5==1 , fe cluster(country_id)
eststo: xtreg breakdown_lexical_5 L.SEI  L.v2peapsecon_2 L.latent_gdppc_mean_log i.year if L.lexical_index_5==1 , fe cluster(country_id)
eststo: xtreg breakdown_lexical_5 L.SEI  L.v2peapsecon_2 L.latent_gdppc_mean_log L.e_migdpgro L.oil_pc_ln L.region_lexical_5 L.v2svstterr i.year if L.lexical_index_5==1, cluster(country_id) fe

estout,  cells(b(star fmt(%9.3f)) se(par) t(fmt(%9.2f)))   /// 
  stats(N N_g, fmt(%9.0f %9.0g) labels(Obs Countries)) starlevels(† 0.1 * 0.05  ** 0.01 *** 0.001) style(fixed) drop(*.year)
esttab using output_TA10.rtf, b(3) se(3) se star(† 0.1 * 0.05 ** 0.01 *** 0.001) stats(N N_g, labels("Observations" "Countries") fmt(0 0)) drop(*.year)
eststo clear




**************************************************
*************** Functional Form ******************
**************************************************

*****************
*** Figure A9 ***
*****************
binscatter transition_lexical_5 SEI if L.lexical_index_5 ==0, xtitle(Ethnic Inequality) ytitle(Probability of Transition) name(fgA9)

graph export "fgA9.pdf", replace


*****************
*** Table A11 ***
*****************
eststo: xtreg transition_lexical_5 L.SEI L.c.SEI#L.c.SEI i.year if L.lexical_index_5==0 , fe cluster(country_id)
eststo: xtreg transition_lexical_5 L.SEI L.c.SEI#L.c.SEI L.latent_gdppc_mean_log i.year if L.lexical_index_5==0 , fe cluster(country_id)
eststo: xtreg transition_lexical_5 L.SEI L.c.SEI#L.c.SEI L.latent_gdppc_mean_log L.e_migdpgro L.oil_pc_ln L.region_lexical_5 L.v2svstterr i.year if L.lexical_index_5==0, fe cluster(country_id)

estout,  cells(b(star fmt(%9.3f)) se(par) t(fmt(%9.2f)))   /// 
  stats(N N_g, fmt(%9.0f %9.0g) labels(Obs Countries)) starlevels(† 0.1 * 0.05  ** 0.01 *** 0.001) style(fixed) drop(*.year)
esttab using output_TA11.rtf, b(3) se(3) se star(† 0.1 * 0.05 ** 0.01 *** 0.001) stats(N N_g, labels("Observations" "Countries") fmt(0 0)) drop(*.year)
eststo clear



****************************************************
*********** Table A12: Transitions type **********
****************************************************

********** Variables ********

* Incumbent and cooperative
gen transition_incumbent = 0
replace transition_incumbent = 1 if transition_type==1 & transition_lexical_5==1
replace transition_incumbent = 1 if transition_type==2 & transition_lexical_5==1
replace transition_incumbent = . if transition_type==.
* Opposition-led
gen transition_opposition = 0
replace transition_opposition = 1 if transition_type==3 & transition_lexical_5==1
replace transition_opposition = . if transition_type==.


* Analysis
eststo: xtreg transition_incumbent L.SEI i.year if L.lexical_index_5==0 , fe cluster(country_id)
eststo: xtreg transition_incumbent L.SEI L.latent_gdppc_mean_log i.year if L.lexical_index_5==0 , fe cluster(country_id)
eststo: xtreg transition_incumbent L.SEI L.latent_gdppc_mean_log L.e_migdpgro L.oil_pc_ln L.region_lexical_5 L.v2svstterr i.year if L.lexical_index_5==0, fe cluster(country_id)

eststo: xtreg transition_opposition L.SEI i.year if L.lexical_index_5==0 , fe cluster(country_id)
eststo: xtreg transition_opposition L.SEI L.latent_gdppc_mean_log i.year if L.lexical_index_5==0 , fe cluster(country_id)
eststo: xtreg transition_lexical_5 L.SEI L.latent_gdppc_mean_log L.e_migdpgro L.oil_pc_ln L.region_lexical_5 L.v2svstterr i.year if L.lexical_index_5==0, fe cluster(country_id)

estout,  cells(b(star fmt(%9.3f)) se(par) t(fmt(%9.2f)))   /// 
  stats(N N_g, fmt(%9.0f %9.0g) labels(Obs Countries)) starlevels(† 0.1 * 0.05  ** 0.01 *** 0.001) style(fixed) drop(*.year)
esttab using output_TA12.rtf, b(3) se(3) se star(† 0.1 * 0.05 ** 0.01 *** 0.001) stats(N N_g, labels("Observations" "Countries") fmt(0 0)) drop(*.year)
eststo clear



 
****************************************
***** Tables A13: Breakdown type *****
****************************************

*** Generate variables ***

* Incumbent
gen breakdown_incumbent = 0
replace breakdown_incumbent = 1 if breakdown_type==1 & breakdown_lexical_5==1
replace breakdown_incumbent = 1 if breakdown_type==4 & breakdown_lexical_5==1
replace breakdown_incumbent = . if breakdown_type==.

* Coup
gen breakdown_coup = 0
replace breakdown_coup = 1 if breakdown_type==2 & breakdown_lexical_5==1
replace breakdown_coup = . if breakdown_type==.

* Analysis
eststo: xtreg breakdown_incumbent L.SEI i.year if L.lexical_index_5==1 , fe cluster(country_id)
eststo: xtreg breakdown_incumbent L.SEI L.latent_gdppc_mean_log i.year if L.lexical_index_5==1 , fe cluster(country_id)
eststo: xtreg breakdown_incumbent L.SEI L.latent_gdppc_mean_log L.e_migdpgro L.oil_pc_ln L.region_lexical_5 L.v2svstterr i.year if L.lexical_index_5==1, cluster(country_id) fe

eststo: xtreg breakdown_coup L.SEI i.year if L.lexical_index_5==1 , fe cluster(country_id)
eststo: xtreg breakdown_coup L.SEI L.latent_gdppc_mean_log i.year if L.lexical_index_5==1 , fe cluster(country_id)
eststo: xtreg breakdown_coup L.SEI L.latent_gdppc_mean_log L.e_migdpgro L.oil_pc_ln L.region_lexical_5 L.v2svstterr i.year if L.lexical_index_5==1, cluster(country_id) fe

estout,  cells(b(star fmt(%9.3f)) se(par) t(fmt(%9.2f)))   /// 
  stats(N N_g, fmt(%9.0f %9.0g) labels(Obs Countries)) starlevels(† 0.1 * 0.05  ** 0.01 *** 0.001) style(fixed) drop(*.year)
esttab using output_TA13.rtf, b(3) se(3) se star(† 0.1 * 0.05 ** 0.01 *** 0.001) stats(N N_g, labels("Observations" "Countries") fmt(0 0)) drop(*.year)
eststo clear



*********************************************************************
*********** Tables A14-A15: Alternative democracy measures **********
*********************************************************************

* LIED 4
eststo: xtreg transition_lexical_4 L.SEI i.year if L.lexical_index_4==0 , fe cluster(country_id)
eststo: xtreg transition_lexical_4 L.SEI L.latent_gdppc_mean_log i.year if L.lexical_index_4==0 , fe cluster(country_id)
eststo: xtreg transition_lexical_4 L.SEI L.latent_gdppc_mean_log L.e_migdpgro L.oil_pc_ln L.region_lexical_4 L.v2svstterr i.year if L.lexical_index_4==0, fe cluster(country_id)

eststo: xtreg breakdown_lexical_4 L.SEI i.year if L.lexical_index_4==1 , fe cluster(country_id)
eststo: xtreg breakdown_lexical_4 L.SEI L.latent_gdppc_mean_log i.year if L.lexical_index_4==1 , fe cluster(country_id)
eststo: xtreg breakdown_lexical_4 L.SEI L.latent_gdppc_mean_log L.e_migdpgro L.oil_pc_ln L.region_lexical_4 L.v2svstterr i.year if L.lexical_index_4==1, cluster(country_id) fe

estout,  cells(b(star fmt(%9.3f)) se(par) t(fmt(%9.2f)))   /// 
  stats(N N_g, fmt(%9.0f %9.0g) labels(Obs Countries)) starlevels(† 0.1 * 0.05  ** 0.01 *** 0.001) style(fixed) drop(*.year)
esttab using output_TA14.rtf, b(3) se(3) se star(† 0.1 * 0.05 ** 0.01 *** 0.001) stats(N N_g, labels("Observations" "Countries") fmt(0 0)) drop(*.year)
eststo clear


* LIED 6
eststo: xtreg transition_lexical_6 L.SEI i.year if L.lexical_index_6==0 , fe cluster(country_id)
eststo: xtreg transition_lexical_6 L.SEI L.latent_gdppc_mean_log i.year if L.lexical_index_6==0 , fe cluster(country_id)
eststo: xtreg transition_lexical_6 L.SEI L.latent_gdppc_mean_log L.e_migdpgro L.oil_pc_ln L.region_lexical_6 L.v2svstterr i.year if L.lexical_index_6==0, fe cluster(country_id)

eststo: xtreg breakdown_lexical_6 L.SEI i.year if L.lexical_index_6==1 , fe cluster(country_id)
eststo: xtreg breakdown_lexical_6 L.SEI L.latent_gdppc_mean_log i.year if L.lexical_index_6==1 , fe cluster(country_id)
eststo: xtreg breakdown_lexical_6 L.SEI L.latent_gdppc_mean_log L.e_migdpgro L..oil_pc_ln L.region_lexical_6 L.v2svstterr i.year if L.lexical_index_6==1, cluster(country_id) fe


estout,  cells(b(star fmt(%9.3f)) se(par) t(fmt(%9.2f)))   /// 
  stats(N N_g, fmt(%9.0f %9.0g) labels(Obs Countries)) starlevels(† 0.1 * 0.05  ** 0.01 *** 0.001) style(fixed) drop(*.year)
esttab using output_TA15.rtf, b(3) se(3) se star(† 0.1 * 0.05 ** 0.01 *** 0.001) stats(N N_g, labels("Observations" "Countries") fmt(0 0)) drop(*.year)
eststo clear





*******************************************************************************************************************
************ Figure A10: Alternative ethnic inequality measure - Breakdown with Houle measure *********************
*******************************************************************************************************************
g lbgi1_2 = ((lbgi1-.000169))/(6.53002-.000169)*(1-0)+0
g lwgi1_2 = ((lwgi1-.13603))/(.692942-.13603)*(1-0)+0

eststo M21: xtreg breakdown_lexical_5 L.SEI L.latent_gdppc_mean_log i.year if L.lexical_index_5==1 , fe cluster(country_id)
eststo M22: xtreg breakdown_lexical_5 L.ggini_2 L.latent_gdppc_mean_log i.year if L.lexical_index_5==1 , fe cluster(country_id)
eststo M23: reg breakdown_lexical_5 L.NHIxl_2 L.latent_gdppc_mean_log i.decade if L.lexical_index_5==1, cluster(country_id)
eststo M24: reg breakdown_lexical_5 L.CL_low1_overlap_2 L.latent_gdppc_mean_log i.decade if L.lexical_index_5==1, cluster(country_id)
eststo M25: reg breakdown_lexical_5 cL.lbgi1_2##cL.lwgi1_2 L.latent_gdppc_mean_log i.decade if L.lexical_index_5==1, cluster(country_id)

coefplot (M21, label(Coppedge et al.)) (M22, label(Omoeva et al.)) (M23, label(Cederman et al. 2013)) (M24, label(Cederman et al. 2015)) (M25, label(Houle 2015)), drop(_cons L.latent_gdppc_mean_log i.year i.decade *year *decade L.lbgi1_2 L.lwgi1_2) level(95) xline(0, lpattern(dash) lcolor(gs10%70)) ciopts(color(black) recast(rcap)) scheme(s2mono)  graphregion(fcolor(white) lcolor(black) lwidth(tiny)) coeflabel(L.SEI = "Coppedge et al. (2021)" L.ggini_2 = "Omoeva et al. (2018)" L.NHIxl_2 = "Cederman et al. (2013)"  L.CL_low1_overlap_2 = "Cederman et al. (2015)"  cL.lbgi1_2#cL.lwgi1_2 = "Houle (2015)", labsize(medsmall)) title("Ethnic inequality and democratic breakdowns", size(medsmall)) subtitle("") msymbol(O) mcolor(black) legend(off) xlabel(, nogrid) ylabel(, nogrid) offset(0) grid(none) name(fgA10)

graph export "fgA10.pdf", replace
eststo clear

***************************************************************************************************
************ Table A16: Cederman et al. and Houle measures with probit ****************************
***************************************************************************************************

eststo: probit breakdown_lexical_5 L.NHIxl_2 L.latent_gdppc_mean_log i.decade if L.lexical_index_5==1, cluster(country_id)
eststo: probit breakdown_lexical_5 L.CL_low1_overlap_2 L.latent_gdppc_mean_log i.decade if L.lexical_index_5==1, cluster(country_id)
eststo: probit breakdown_lexical_5 cL.lbgi1_2##cL.lwgi1_2 L.latent_gdppc_mean_log i.decade if L.lexical_index_5==1, cluster(country_id)

estout,  cells(b(star fmt(%9.3f)) se(par) t(fmt(%9.2f)))   /// 
  stats(N N_g, fmt(%9.0f %9.0g) labels(Obs Countries)) starlevels(† 0.1 * 0.05  ** 0.01 *** 0.001) style(fixed) drop(*.decade _cons)
esttab using output_TA16.rtf, b(3) se(3) se star(† 0.1 * 0.05 ** 0.01 *** 0.001) stats(N N_g, labels("Observations" "Countries") fmt(0 0)) drop(*.decade _cons) replace
eststo clear

 
**************************************************************************
********************** Table A17-18: Excluding regions *******************
**************************************************************************

* Transitions
eststo: xtreg transition_lexical_5 L.SEI L.latent_gdppc_mean_log i.year if L.lexical_index_5==0 & e_regionpol_6C!=1 , fe cluster(country_id)
eststo: xtreg transition_lexical_5 L.SEI L.latent_gdppc_mean_log i.year if L.lexical_index_5==0 & e_regionpol_6C!=2 , fe cluster(country_id)
eststo: xtreg transition_lexical_5 L.SEI L.latent_gdppc_mean_log i.year if L.lexical_index_5==0 & e_regionpol_6C!=3 , fe cluster(country_id)
eststo: xtreg transition_lexical_5 L.SEI L.latent_gdppc_mean_log i.year if L.lexical_index_5==0 & e_regionpol_6C!=4 , fe cluster(country_id)
eststo: xtreg transition_lexical_5 L.SEI L.latent_gdppc_mean_log i.year if L.lexical_index_5==0 & e_regionpol_6C!=5 , fe cluster(country_id)
eststo: xtreg transition_lexical_5 L.SEI L.latent_gdppc_mean_log i.year if L.lexical_index_5==0 & e_regionpol_6C!=6 , fe cluster(country_id)

estout,  cells(b(star fmt(%9.3f)) se(par) t(fmt(%9.2f)))   /// 
  stats(r2_a N , fmt(%9.3f %9.0g) labels(R-squared Obs)) starlevels(† 0.1 * 0.05  ** 0.01 *** 0.001) style(fixed) drop(*.year)
esttab using output_TA17.rtf, b(3) se(3) se star(† 0.1 * 0.05 ** 0.01 *** 0.001) stats(N N_g, labels("Observations" "Countries") fmt(0 0)) drop(*.year)
eststo clear

* Breakdowns
eststo: xtreg breakdown_lexical_5 L.SEI L.latent_gdppc_mean_log i.year if L.lexical_index_5==1 & e_regionpol_6C!=1 , fe cluster(country_id)
eststo: xtreg breakdown_lexical_5 L.SEI L.latent_gdppc_mean_log i.year if L.lexical_index_5==1 & e_regionpol_6C!=2 , fe cluster(country_id)
eststo: xtreg breakdown_lexical_5 L.SEI L.latent_gdppc_mean_log i.year if L.lexical_index_5==1 & e_regionpol_6C!=3 , fe cluster(country_id)
eststo: xtreg breakdown_lexical_5 L.SEI L.latent_gdppc_mean_log i.year if L.lexical_index_5==1 & e_regionpol_6C!=4 , fe cluster(country_id)
eststo: xtreg breakdown_lexical_5 L.SEI L.latent_gdppc_mean_log i.year if L.lexical_index_5==1 & e_regionpol_6C!=5 , fe cluster(country_id)
eststo: xtreg breakdown_lexical_5 L.SEI L.latent_gdppc_mean_log i.year if L.lexical_index_5==1 & e_regionpol_6C!=6 , fe cluster(country_id)

estout,  cells(b(star fmt(%9.3f)) se(par) t(fmt(%9.2f)))   /// 
  stats(N N_g, fmt(%9.0f %9.0g) labels(Obs Countries)) starlevels(† 0.1 * 0.05  ** 0.01 *** 0.001) style(fixed) drop(*.year)
esttab using output_TA18.rtf, b(3) se(3) se star(† 0.1 * 0.05 ** 0.01 *** 0.001) stats(N N_g, labels("Observations" "Countries") fmt(0 0)) drop(*.year)
eststo clear



**************************************************************************
*************** Table A19: Temporally restricted sample ******************
**************************************************************************

eststo: xtreg transition_lexical_5 L.SEI i.year if L.lexical_index_5==0 & year >=1960, fe cluster(country_id)
eststo: xtreg transition_lexical_5 L.SEI L.latent_gdppc_mean_log i.year if L.lexical_index_5==0 & year >=1960, fe cluster(country_id)
eststo: xtreg transition_lexical_5 L.SEI L.latent_gdppc_mean_log L.e_migdpgro L.oil_pc_ln L.region_lexical_5 L.v2svstterr i.year if L.lexical_index_5==0 & year >=1960, fe cluster(country_id)

eststo: xtreg breakdown_lexical_5 L.SEI i.year if L.lexical_index_5==1 & year >=1960, fe cluster(country_id)
eststo: xtreg breakdown_lexical_5 L.SEI L.latent_gdppc_mean_log i.year if L.lexical_index_5==1 & year >=1960, fe cluster(country_id)
eststo: xtreg breakdown_lexical_5 L.SEI L.latent_gdppc_mean_log L.e_migdpgro L.oil_pc_ln L.region_lexical_5 L.v2svstterr i.year if L.lexical_index_5==1 & year >=1960, cluster(country_id) fe

estout,  cells(b(star fmt(%9.3f)) se(par) t(fmt(%9.2f)))   /// 
  stats(N N_g, fmt(%9.0f %9.0g) labels(Obs Countries)) starlevels(† 0.1 * 0.05  ** 0.01 *** 0.001) style(fixed) drop(*.year)
esttab using output_TA19.rtf, b(3) se(3) se star(† 0.1 * 0.05 ** 0.01 *** 0.001) stats(N N_g, labels("Observations" "Countries") fmt(0 0)) drop(*.year)
eststo clear




**********************************************************************
******************** Table A20: Longer lags  *************************
**********************************************************************

* Transitions (5 years)
eststo: xtreg transition_lexical_5 L5.SEI i.year if L5.lexical_index_5==0 , fe cluster(country_id)
eststo: xtreg transition_lexical_5 L5.SEI L5.latent_gdppc_mean_log i.year if L5.lexical_index_5==0 , fe cluster(country_id)
eststo: xtreg transition_lexical_5 L5.SEI L5.latent_gdppc_mean_log L5.e_migdpgro L5.oil_pc_ln L5.region_lexical_5 L5.v2svstterr i.year if L5.lexical_index_5==0, fe cluster(country_id)


* Breakdowns (5 years)
eststo: xtreg breakdown_lexical_5 L5.SEI i.year if L5.lexical_index_5==1 , fe cluster(country_id)
eststo: xtreg breakdown_lexical_5 L5.SEI L5.latent_gdppc_mean_log i.year if L5.lexical_index_5==1 , fe cluster(country_id)
eststo: xtreg breakdown_lexical_5 L5.SEI L5.latent_gdppc_mean_log L5.e_migdpgro L5.oil_pc_ln L5.region_lexical_5 L5.v2svstterr i.year if L5.lexical_index_5==1, cluster(country_id) fe

estout,  cells(b(star fmt(%9.3f)) se(par) t(fmt(%9.2f)))   /// 
  stats(N N_g, fmt(%9.0f %9.0g) labels(Obs Countries)) starlevels(† 0.1 * 0.05  ** 0.01 *** 0.001) style(fixed) drop(*.year)
esttab using output_TA20.rtf, b(3) se(3) se star(† 0.1 * 0.05 ** 0.01 *** 0.001) stats(N N_g, labels("Observations" "Countries") fmt(0 0)) drop(*.year)
eststo clear


*******************************************************************
******************* Table A21: Longer panels  *********************
*******************************************************************


********************************* five, ten and twenty year panels
gen fiveyears=1 if year==1900| year==1905| year==1910| year==1915| year==1920| year==1925| year==1930| year==1935| year==1940| year==1945| year==1950| year==1955| year==1960| year==1965| year==1970| year==1975| year==1980| year==1985| year==1990| year==1995| year==2000| year==2005| year==2010| year==2015| year==2020
gen tenyears=1 if year==1900| year==1910| year==1920| year==1930| year==1940| year==1950| year==1960| year==1970| year==1980| year==1990| year==2000| year==2010| year==2020
gen twentyyears=1 if year==1900| year==1920| year==1940| year==1960| year==1980| year==2000| year== 2020


*** With LIED 5 as outcome

* 5 years (To democracy)
eststo: xtreg lexical_index_5 L.SEI i.year if L.lexical_index_5==0 & fiveyears==1, fe cluster(country_id)
eststo: xtreg lexical_index_5 L.SEI L.latent_gdppc_mean_log i.year if L.lexical_index_5==0 & fiveyears==1, fe cluster(country_id)
eststo: xtreg lexical_index_5 L.SEI L.latent_gdppc_mean_log L.e_migdpgro L.oil_pc_ln L.region_lexical_5 L.v2svstterr i.year if L.lexical_index_5==0 & fiveyears==1, fe cluster(country_id)
  
  * 10 years (To democracy)
eststo: xtreg lexical_index_5 L.SEI i.year if L.lexical_index_5==0 & tenyears==1, fe cluster(country_id)
eststo: xtreg lexical_index_5 L.SEI L.latent_gdppc_mean_log i.year if L.lexical_index_5==0 & tenyears==1, fe cluster(country_id)
eststo: xtreg lexical_index_5 L.SEI L.latent_gdppc_mean_log L.e_migdpgro L.oil_pc_ln L.region_lexical_5 L.v2svstterr i.year if L.lexical_index_5==0 & tenyears==1, fe cluster(country_id)

* 20 years (To democracy)
eststo: xtreg lexical_index_5 L.SEI i.year if L.lexical_index_5==0 & twentyyears==1, fe cluster(country_id)
eststo: xtreg lexical_index_5 L.SEI L.latent_gdppc_mean_log i.year if L.lexical_index_5==0 & twentyyears==1, fe cluster(country_id)
eststo: xtreg lexical_index_5 L.SEI L.latent_gdppc_mean_log L.e_migdpgro L.oil_pc_ln L.region_lexical_5 L.v2svstterr i.year if L.lexical_index_5==0 & twentyyears==1, fe cluster(country_id)

estout,  cells(b(star fmt(%9.3f)) se(par) t(fmt(%9.2f)))   /// 
  stats(N N_g, fmt(%9.0f %9.0g) labels(Obs Countries)) starlevels(† 0.1 * 0.05  ** 0.01 *** 0.001) style(fixed) drop(*.year)
esttab using output_TA21.rtf, b(3) se(3) se star(† 0.1 * 0.05 ** 0.01 *** 0.001) stats(N N_g, labels("Observations" "Countries") fmt(0 0)) drop(*.year)
eststo clear



**************************************************************************
*************** Table A22: Regime type spell length **********************
**************************************************************************
eststo: xtreg transition_lexical_5 L.SEI L.years_autocratic L.years_autocratic_2 L.years_autocratic_3 if L.lexical_index_5==0 , fe cluster(country_id)
eststo: xtreg transition_lexical_5 L.SEI L.latent_gdppc_mean_log L.years_autocratic L.years_autocratic_2 L.years_autocratic_3 if L.lexical_index_5==0 , fe cluster(country_id)
eststo: xtreg transition_lexical_5 L.SEI L.latent_gdppc_mean_log L.e_migdpgro L.oil_pc_ln L.region_lexical_5 L.v2svstterr L.years_autocratic L.years_autocratic_2 L.years_autocratic_3 if L.lexical_index_5==0, fe cluster(country_id)

eststo: xtreg breakdown_lexical_5 L.SEI L.years_democratic L.years_democratic_2 L.years_democratic_3 if L.lexical_index_5==1 , fe cluster(country_id)
eststo: xtreg breakdown_lexical_5 L.SEI L.latent_gdppc_mean_log L.years_democratic L.years_democratic_2 L.years_democratic_3 if L.lexical_index_5==1 , fe cluster(country_id)
eststo: xtreg breakdown_lexical_5 L.SEI L.latent_gdppc_mean_log L.e_migdpgro L.oil_pc_ln L.region_lexical_5 L.v2svstterr L.years_democratic L.years_democratic_2 L.years_democratic_3 if L.lexical_index_5==1, cluster(country_id) fe

estout,  cells(b(star fmt(%9.3f)) se(par) t(fmt(%9.2f)))   /// 
  stats(N N_g, fmt(%9.0f %9.0g) labels(Obs Countries)) starlevels(† 0.1 * 0.05  ** 0.01 *** 0.001) style(fixed)   
esttab using output_TA22.rtf, b(3) se(3) se star(† 0.1 * 0.05 ** 0.01 *** 0.001) stats(N N_g, labels("Observations" "Countries") fmt(0 0))
eststo clear


*********************************************************
*********** Table A23: Main results with Probit *********
*********************************************************

* SEI
eststo: probitfe transition_lexical_5 L.SEI i.decade if L.lexical_index_5==0
eststo: probitfe transition_lexical_5 L.SEI L.latent_gdppc_mean_log i.decade if L.lexical_index_5==0
eststo: probitfe transition_lexical_5 L.SEI L.latent_gdppc_mean_log L.e_migdpgro L.oil_pc_ln L.region_lexical_5 L.v2svstterr i.decade if L.lexical_index_5==0

eststo: probitfe breakdown_lexical_5 L.SEI i.decade if L.lexical_index_5==1
eststo: probitfe breakdown_lexical_5 L.SEI L.latent_gdppc_mean_log i.decade if L.lexical_index_5==1
eststo: probitfe breakdown_lexical_5 L.SEI L.latent_gdppc_mean_log L.e_migdpgro L.oil_pc_ln L.region_lexical_5 L.v2svstterr i.decade if L.lexical_index_5==1

estout,  cells(b(star fmt(%9.3f)) se(par) t(fmt(%9.2f)))   /// 
  stats(N N_g, fmt(%9.0f %9.0g) labels(Obs Countries)) starlevels(† 0.1 * 0.05  ** 0.01 *** 0.001) style(fixed) drop(*decade)
esttab using output_TA23.rtf, b(3) se(3) se star(† 0.1 * 0.05 ** 0.01 *** 0.001) stats(N N_g, labels("Observations" "Countries") fmt(0 0)) drop(*decade)
eststo clear


*********************************************************
***************** Size of excluded groups ***************
*********************************************************

*** Table A24: Transitions ***
eststo: xtreg transition_lexical_5 c.L.SEI##c.L.exclpop L.latent_gdppc_mean_log i.year if L.lexical_index_5==0 , fe cluster(country_id)
eststo: xtreg transition_lexical_5 c.L.SEI##c.L.discrimpop L.latent_gdppc_mean_log i.year if L.lexical_index_5==0 , fe cluster(country_id)

estout,  cells(b(star fmt(%9.3f)) se(par) t(fmt(%9.2f)))   /// 
  stats(N N_g, fmt(%9.0f %9.0g) labels(Obs Countries)) starlevels(† 0.1 * 0.05  ** 0.01 *** 0.001) style(fixed) drop(*.year)
esttab using output_TA24.rtf, b(3) se(3) se star(† 0.1 * 0.05 ** 0.01 *** 0.001) stats(N N_g, labels("Observations" "Countries") fmt(0 0)) drop(*.year)
eststo clear

* Interflex cannot lag variables, lagged variables created manually
g LSEI = L.SEI
g Llatent_gdppc_mean_log  = L.latent_gdppc_mean_log
g Lexclpop = L.exclpop

*** Figure A11  ***
set scheme plotplain
interflex transition_lexical_5 LSEI Lexclpop Llatent_gdppc_mean_log if L.lexical_index_5==0, fe(country_id year) cluster(country_id) ylabel(Demo. transitions) dlabel(Ethnic inequality) xlabel(Exclusion)
graph export "fgA11.pdf", replace

*** Table A25: Breakdowns ***
eststo: xtreg breakdown_lexical_5 c.L.SEI##c.L.exclpop L.latent_gdppc_mean_log i.year if L.lexical_index_5==1 , fe cluster(country_id)
eststo: xtreg breakdown_lexical_5 c.L.SEI##c.L.discrimpop L.latent_gdppc_mean_log i.year if L.lexical_index_5==1 , fe cluster(country_id)

estout,  cells(b(star fmt(%9.3f)) se(par) t(fmt(%9.2f)))   /// 
  stats(N N_g, fmt(%9.0f %9.0g) labels(Obs Countries)) starlevels(† 0.1 * 0.05  ** 0.01 *** 0.001) style(fixed) drop(*.year)
esttab using output_TA25.rtf, b(3) se(3) se star(† 0.1 * 0.05 ** 0.01 *** 0.001) stats(N N_g, labels("Observations" "Countries") fmt(0 0)) drop(*.year)
eststo clear

*** Figure A12 ***
interflex breakdown_lexical_5 LSEI Lexclpop Llatent_gdppc_mean_log if L.lexical_index_5==1, fe(country_id year) cluster(country_id) ylabel(Breakdowns) dlabel(Ethnic inequality) xlabel(Exclusion)
graph export "fgA12.pdf", replace


**************************************************************************
********************  Check for influential observations *****************
**************************************************************************


*** Table A26: Transition baseline ***
reg transition_lexical_5 L.SEI L.latent_gdppc_mean_log i.country_id i.year if L.lexical_index_5==0
predict tempdfbeta, dfbeta(L.SEI)
summarize tempdfbeta if abs(tempdfbeta) > 2/sqrt(e(N))
bro country_name year transition_lexical_5 tempdfbeta if abs(tempdfbeta) >2/sqrt(e(N)) & tempdfbeta <.

drop tempdfbeta


*** Table A27: Breakdown baseline ***
reg breakdown_lexical_5 L.SEI L.latent_gdppc_mean_log i.country_id i.year if L.lexical_index_5==1
predict tempdfbeta, dfbeta(L.SEI)
summarize tempdfbeta if abs(tempdfbeta) > 2/sqrt(e(N))
bro country_name year breakdown_lexical_5 tempdfbeta if abs(tempdfbeta) >2/sqrt(e(N)) & tempdfbeta <.





*****************************************************************************************************
*****************************************************************************************************
************************************ Group-level data ***********************************************
*****************************************************************************************************
*****************************************************************************************************


* Open dataset
use "AMAR dataset for analysis", replace

* Lexical level 5 variable *
gen lexical_index_5= 1 if lexical_index >= 5
replace lexical_index_5 = 0 if lexical_index <=4
replace lexical_index_5 = . if lexical_index ==.


*** AUTOCRACIES ***

* Table A2: Association between economic discrimination and economic grievances (autocratic sample)
eststo: reg ECGR ECDIS latent_gdppc_mean_log i.country_id if lexical_index_5==0, cluster(NUMCODE)

estout,  cells(b(star fmt(%9.3f)) se(par) t(fmt(%9.2f)))   /// 
  stats(r2_a N N_g, fmt(%9.0f %9.0g) labels(R-squared Obs)) starlevels(† 0.1 * 0.05  ** 0.01 *** 0.001) style(fixed) drop(*country_id)
esttab using output_TA2.rtf, b(3) se(3) se star(† 0.1 * 0.05 ** 0.01 *** 0.001) stats(N N_g, fmt(%9.0f %9.0g)) drop(*country_id)
eststo clear


* Table A3: Association between economic grievances and protests, rebellion, and repression (autocratic sample)
eststo: reg PROT ECGR latent_gdppc_mean_log i.country_id if lexical_index_5==0, cluster(NUMCODE)
eststo: reg REB ECGR latent_gdppc_mean_log i.country_id if lexical_index_5==0, cluster(NUMCODE)
eststo: reg REPVIOL ECGR latent_gdppc_mean_log i.country_id if lexical_index_5==0, cluster(NUMCODE)
eststo: reg REPNVIOL ECGR latent_gdppc_mean_log i.country_id if lexical_index_5==0, cluster(NUMCODE)

estout,  cells(b(star fmt(%9.3f)) se(par) t(fmt(%9.2f)))   /// 
  stats(N N_g, fmt(%9.0f %9.0g) labels(Obs Countries)) starlevels(† 0.1 * 0.05  ** 0.01 *** 0.001) style(fixed) drop(*country_id)
esttab using output_TA3.rtf, b(3) se(3) se star(† 0.1 * 0.05 ** 0.01 *** 0.001) stats(N N_g, labels("Observations" "Groups") fmt(0 0)) drop(*country_id)
eststo clear
 
 
*** DEMOCRACIES ***

* Table A4: Association between economic discrimination and economic grievances (democratic sample)
eststo: reg ECGR ECDIS latent_gdppc_mean_log i.country_id if lexical_index_5==1, cluster(NUMCODE)

estout,  cells(b(star fmt(%9.3f)) se(par) t(fmt(%9.2f)))   /// 
  stats(r2_a N , fmt(%9.3f %9.0g) labels(R-squared Obs)) starlevels(† 0.1 * 0.05  ** 0.01 *** 0.001) style(fixed) drop(*country_id)
esttab using output_TA4.rtf, b(3) se(3) se star(† 0.1 * 0.05 ** 0.01 *** 0.001) stats(N, fmt(0 3)) drop(*country_id)
eststo clear
 
* Table A5: Association between economic grievances and protests, rebellion, and repression (democratic sample)
eststo: reg PROT ECGR latent_gdppc_mean_log i.country_id if lexical_index_5==1, cluster(NUMCODE)
eststo: reg REB ECGR latent_gdppc_mean_log i.country_id if lexical_index_5==1, cluster(NUMCODE)
eststo: reg REPVIOL ECGR latent_gdppc_mean_log i.country_id if lexical_index_5==1, cluster(NUMCODE)
eststo: reg REPNVIOL ECGR latent_gdppc_mean_log i.country_id if lexical_index_5==1, cluster(NUMCODE)

estout,  cells(b(star fmt(%9.3f)) se(par) t(fmt(%9.2f)))   /// 
  stats(N N_g, fmt(%9.0f %9.0g) labels(Obs Countries)) starlevels(† 0.1 * 0.05  ** 0.01 *** 0.001) style(fixed) drop(*country_id)
esttab using output_TA5.rtf, b(3) se(3) se star(† 0.1 * 0.05 ** 0.01 *** 0.001) stats(N N_g, labels("Observations" "Groups") fmt(0 0)) drop(*country_id)
eststo clear

***
log close
translate log_ethnic_ineq_reg.log log_ethnic_ineq_reg.pdf
